function ccR_Mage_2()
	if ccrPlayerLevel() == 90 then ccR_Mage_Fire_90() end
end

function ccR_Mage_Fire_90()
	--[[
		Noxxic 5.4.8
		1. Combustion with Ignite on the target.
		2. Pyroblast with Pyroblast! proc.
		3. Inferno Blast when Heating Up procs.
		4. Living Bomb refresh with < 1 tick remaining.
		5. Fireball as a filler spell.
		6. Scorch if moving.
	]]

	local vTargetCount = ccrTargetCount(12)
	-- Single Target Rotation
	if vTargetCount >= 1 then
		-- Player is moving
		if ccrPlayerIsMoving() then
			-- Pyroblast
			if ccrPlayerHasBuff(PYROBLAST_BUFF) then
				ccrCastAttack(PYROBLAST)
				return
			end
			-- Living Bomb
			if (not ccrTargetHasMyDebuff(LIVING_BOMB)
			or	ccrTargetHasMyDebuffRemaining(LIVING_BOMB, 1))
			then
				ccrCastAttack(LIVING_BOMB)
				return
			end
			-- Scorch
			if ccrSpellCanAttack(SCORCH) then
				ccrCastAttack(SCORCH)
				return
			end
		else
		-- Player is stood still

			-- Alter Time
			if ccrPlayerHasBuff(INVOCATION)
			and ccrPlayerHasBuff(PYROBLAST_BUFF)
			and ccrSpellIsReady(ALTER_TIME)
			then
				ccrCast(ALTER_TIME)
				return
			end

			-- Invocation
			if ccrPlayerHasTalent(INVOCATION)
			and not ccrPlayerHasBuff(INVOKERS_ENERGY)
			and ccrSpellIsReady(EVOCATION)
			and not ccrPlayerIsCastingOrChanneling()
			then
				ccrCast(EVOCATION)
				return
			end

			-- Mirror Image on Boss
			if ccrTargetIsBoss()
			and ccrSpellIsReady(MIRROR_IMAGE)
			and not ccrPlayerIsCastingOrChanneling()
			then
				ccrCast(MIRROR_IMAGE)
				return
			end

			-- AoE
			if vTargetCount >= 7 then
				-- Fire Strike
				if ccrSpellIsReady(FLAMESTRIKE) 
				and not ccrPlayerIsMoving()
				then
					ccrCast(FLAMESTRIKE)
					if SpellIsTargeting() == 1 then CastAtLocation(Target:GetLocation()) end
				end
				-- Arcane Explosion on mobs around the player
				if #tblPGetMeleeEnemies >= 5
				and ccrSpellIsReady(ARCANE_EXPLOSION)
				then
					ccrCast(ARCANE_EXPLOSION)
				end
			end

			-- 1
			if ccrTargetHasMyDebuff(IGNITE)
			and ccrSpellIsReady(COMBUSTION)
			then
				ccrCast(COMBUSTION)
				return
			end
			-- 2
			if ccrPlayerHasBuff(PYROBLAST_BUFF) then
				ccrCastAttack(PYROBLAST)
				return
			end
			-- 3
			if ccrPlayerHasBuff(HEATING_UP)
			and ccrSpellCanAttack(INFERNO_BLAST)
			then
				ccrCastAttack(INFERNO_BLAST)
				return
			end
			-- 4
			if (not ccrTargetHasMyDebuff(LIVING_BOMB)
			or	ccrTargetHasMyDebuffRemaining(LIVING_BOMB, 1))
			then
				ccrCastAttack(LIVING_BOMB)
				return
			end
			-- 5
			if ccrSpellCanAttack(FIREBALL) then
				ccrCastAttack(FIREBALL)
				return
			end
		end
	end
end

function Mage_Fire_default_action_list()
	-- 9	12.01	counterspell,if=target.debuff.casting.react
	if ccrTargetIsCastingOrChanneling()
	and ccrSpellCanAttack(COUNTERSPELL)
	then
		ccrCastAttack(COUNTERSPELL)
	end

	-- A	0.00	cancel_buff,name=alter_time,moving=1
	if ccrPlayerHasBuff(ALTER_TIME)
	and ccrPlayerIsMoving()
	then
		RunMacroText("/cancelaura Alter Time")
	end

	--cold_snap,if=talent.cold_snap.enabled&health.pct<30
	if ccrPlayerHasTalent(COLD_SNAP)
	and ccrPlayerHealth() <= 30
	and ccrSpellIsReady(COLD_SNAP)
	then
		ccrCast(COLD_SNAP)
	end

	-- time_warp,if=buff.alter_time.down
	if ccrSpellIsReady(TIME_WARP)
	and not ccrSpellIsReady(ALTER_TIME)
	then
		ccrCast(TIME_WARP)
	end

	-- mana_gem,if=mana.pct<10 
	if ccrPlayerMana() <= 10
	and GetItemCount("Mana Gem") > 0
	and IsUsableItem("Mana Gem") == 1
	then
		UseItemByName("Mana Gem")
	end

	-- rune_of_power,if=talent.rune_of_power.enabled&buff.rune_of_power.remains=0
	if ccrPlayerHasTalent(RUNE_OF_POWER)
	and not ccrPlayerHasBuff(RUNE_OF_POWER)
	and ccrSpellIsReady(RUNE_OF_POWER)
	then
		ccrCast(RUNE_OF_POWER)
		if SpellIsTargeting() == 1 then CastAtLocation(Player:GetLocation()) end
	end

	-- cancel_buff,name=alter_time,if=buff.amplified.up&buff.alter_time.up&(trinket.stat.intellect.cooldown_remains-buff.alter_time.remains>109)

	-- run_action_list,name=combust_sequence,if=buff.alter_time.up|pyro_chain
	if ccrPlayerHasBuff(ALTER_TIME) then
		Mage_Fire_combust_sequence()
	end


	-- run_action_list,name=init_alter_combust,if=buff.amplified.up&cooldown.alter_time_activate.up&cooldown.combustion.up&(trinket.stat.intellect.cooldown_remains>95|trinket.stat.intellect.cooldown_remains+20>time_to_die)
	if IsEquippedItem("Purified Bindings of Immerseus") == 1
	and not ccrSpellIsReady(ALTER_TIME)
	and ccrSpellIsReady(COMBUSTION)
	--and GetSpellCooldown(GetSpellInfo(146046)) >= 95
	then
		Mage_Fire_init_alter_combust()
	end

	-- run_action_list,name=init_alter_combust,if=buff.amplified.down&cooldown.alter_time_activate.up&cooldown.combustion.up
	if IsEquippedItem("Purified Bindings of Immerseus") == 1
	and not ccrSpellIsReady(ALTER_TIME)
	and not ccrSpellIsReady(COMBUSTION)
	then
		Mage_Fire_init_alter_combust()
	end

	-- run_action_list,name=init_pom_combust,if=buff.amplified.up&cooldown.alter_time_activate.remains>45&cooldown.combustion.up&cooldown.presence_of_mind.up&(trinket.stat.intellect.cooldown_remains>95|trinket.stat.intellect.cooldown_remains+20>time_to_die)

	-- run_action_list,name=init_pom_combust,if=buff.amplified.down&cooldown.alter_time_activate.remains>45&cooldown.combustion.up&cooldown.presence_of_mind.up
	if IsEquippedItem("Purified Bindings of Immerseus") == nil
	and SpellCDDuration(ALTER_TIME) >= 45
	and ccrSpellIsReady(COMBUSTION)
	and ccrSpellIsReady(PRESENCE_OF_MIND)
	then
		Mage_Fire_init_pom_combust()
	end

	-- rune_of_power,if=talent.rune_of_power.enabled&(buff.alter_time.down&buff.rune_of_power.remains<4*action.fireball.execute_time&(buff.heating_up.down|buff.pyroblast.down|!action.fireball.in_flight))
	-- mirror_image,if=buff.alter_time.down&(buff.heating_up.down|buff.pyroblast.down|!action.fireball.in_flight)
	if not ccrPlayerHasBuff(ALTER_TIME)
	and (not ccrPlayerHasBuff(HEATING_UP) or not ccrPlayerHasBuff(PYROBLAST_BUFF))
	and ccrSpellIsReady(MIRROR_IMAGE)
	then
		ccrCast(MIRROR_IMAGE)
	end

	-- blood_fury,if=buff.alter_time.down&target.time_to_die<18
	-- berserking,if=buff.alter_time.down&target.time_to_die<18
	-- arcane_torrent,if=buff.alter_time.down&target.time_to_die<18
	-- jade_serpent_potion,if=buff.alter_time.down&target.time_to_die<45
	-- use_item,slot=hands,if=buff.alter_time.down&(trinket.stat.intellect.cooldown_remains>50|target.time_to_die<12)
	-- run_action_list,name=aoe,if=active_enemies>=5
	if ccrTargetCount(12) >= 5 then
		Mage_Fire_aoe()
	end
	-- run_action_list,name=proc_builder,if=buff.amplified.up&trinket.stat.intellect.cooldown_remains<action.fireball.execute_time
	-- run_action_list,name=single_target
	Mage_Fire_single_target_action()
end

function Mage_Fire_combust_sequence()
	-- start_pyro_chain,if=!pyro_chain
	-- stop_pyro_chain,if=cooldown.combustion.remains>0&pyro_chain
	-- presence_of_mind,if=talent.presence_of_mind.enabled&buff.alter_time.down
	if ccrPlayerHasTalent(PRESENCE_OF_MIND)
	and not ccrPlayerHasBuff(ALTER_TIME)
	and ccrSpellIsReady(PRESENCE_OF_MIND)
	then
		ccrCast(PRESENCE_OF_MIND)
	end
	-- pyroblast,if=execute_time=gcd&buff.alter_time.up
	-- alter_time,if=buff.alter_time.up&action.pyroblast.execute_time>gcd
	-- pyroblast,if=talent.presence_of_mind.enabled&buff.presence_of_mind.up&buff.pyroblast.up
	if ccrPlayerHasTalent(PRESENCE_OF_MIND)
	and ccrPlayerHasBuff(PRESENCE_OF_MIND)
	and ccrPlayerHasBuff(PYROBLAST_BUFF)
	and ccrSpellCanAttack(PYROBLAST)
	then
		ccrCastAttack(PYROBLAST)
	end
	-- pyroblast,if=!talent.presence_of_mind.enabled&buff.pyroblast.up
	if not ccrPlayerHasTalent(PRESENCE_OF_MIND)
	and ccrPlayerHasBuff(PYROBLAST)
	and ccrSpellCanAttack(PYROBLAST)
	then
		ccrCastAttack(PYROBLAST)
	end
	-- combustion,if=buff.alter_time.down&cooldown.alter_time_activate.remains>150&buff.tempus_repit.up&buff.tempus_repit.remains<gcd
	-- pyroblast,if=buff.presence_of_mind.up&(travel_time+0.15<dot.ignite.remains-4|(crit_damage*crit_pct_current+hit_damage*(100-crit_pct_current))*0.01*mastery_value>dot.ignite.tick_dmg)
	-- pyroblast,if=buff.presence_of_mind.up&buff.heating_up.up&gcd+travel_time+0.15<dot.ignite.remains-2&(crit_damage*crit_pct_current+hit_damage*(100-crit_pct_current))*0.01*(0.0125*crit_pct_current+1)*mastery_value>dot.ignite.tick_dmg
	-- pyroblast,if=buff.presence_of_mind.down&buff.pyroblast.up&(travel_time+0.15<dot.ignite.remains-4|(crit_damage*crit_pct_current+hit_damage*(100-crit_pct_current))*0.01*mastery_value>dot.ignite.tick_dmg)
	-- combustion
end

function Mage_Fire_init_alter_combust()
	-- run_action_list,name=proc_builder,if=buff.pyroblast.down|buff.heating_up.down|!action.fireball.in_fligh
	if not ccrPlayerHasBuff(PYROBLAST_BUFF)
	and not ccrPlayerHasBuff(HEATING_UP)
	then
		Mage_Fire_proc_builder()
	end
	-- blood_fury
	-- berserking
	-- arcane_torrent
	-- jade_serpent_potion
	-- use_item,slot=hands 
	-- presence_of_mind,if=talent.presence_of_mind.enabled
	if ccrPlayerHasTalent(PRESENCE_OF_MIND)
	and ccrSpellIsReady(PRESENCE_OF_MIND)
	then
		ccrCast(PRESENCE_OF_MIND)
	end
	-- alter_time
end

function Mage_Fire_init_pom_combust()
	-- run_action_list,name=proc_builder,if=buff.pyroblast.down|buff.heating_up.down|!action.fireball.in_flight
	-- start_pyro_chain,if=!pyro_chain
end

function Mage_Fire_proc_builder()
	-- pyroblast,if=buff.pyroblast.up&buff.heating_up.up&action.fireball.in_flight
	if ccrPlayerHasBuff(PYROBLAST_BUFF)
	and ccrPlayerHasBuff(HEATING_UP)
	and ccrSpellCanAttack(PYROBLAST)
	then
		ccrCastAttack(PYROBLAST)
	end
	-- nether_tempest,cycle_targets=1,if=talent.nether_tempest.enabled&((!ticking|remains<tick_time)&target.time_to_die>6)
	-- living_bomb,cycle_targets=1,if=talent.living_bomb.enabled&((!ticking|remains<tick_time)&target.time_to_die>tick_time*3)
	-- frost_bomb,if=talent.frost_bomb.enabled&(!ticking&target.time_to_die>cast_time+tick_time)
	if not ccrTargetHasMyDebuff(MAGE_BOMB)
	and ccrSpellCanAttack(MAGE_BOMB)
	then
		ccrCastAttack(MAGE_BOMB)
	end
	-- inferno_blast,if=(buff.pyroblast.down&buff.heating_up.up)|(buff.pyroblast.up&buff.heating_up.down&!action.fireball.in_flight&!action.pyroblast.in_flight)
	-- fireball
	if ccrSpellCanAttack(FIREBALL) then ccrCastAttack(FIREBALL) end
	-- scorch,moving=1
	if ccrPlayerIsMoving()
	and ccrSpellCanAttack(SCORCH)
	then
		ccrCastAttack(SCORCH)
	end	
end

function Mage_Fire_single_target_action()
	-- inferno_blast,if=dot.combustion.ticking&active_enemies>1
	if ccrTargetHasMyDebuff(118271)
	and ccrTargetCount(12) > 1
	and ccrSpellCanAttack(INFERNO_BLAST)
	then
		ccrCastAttack(INFERNO_BLAST)
	end
	-- pyroblast,if=buff.pyroblast.up&buff.pyroblast.remains<action.fireball.execute_time
	if ccrPlayerHasBuff(PYROBLAST_BUFF) then ccrCastAttack(PYROBLAST) end

	-- pyroblast,if=set_bonus.tier16_2pc_caster&buff.pyroblast.up&buff.potent_flames.up&buff.potent_flames.remains<action.fireball.execute_time
	-- scorch,if=set_bonus.tier16_2pc_caster&buff.potent_flames.up&buff.pyroblast.down&buff.heating_up.down&buff.potent_flames.remains<action.fireball.execute_time+gcd&buff.potent_flames.remains>2*gcd
	-- inferno_blast,if=set_bonus.tier16_2pc_caster&buff.pyroblast.down&buff.potent_flames.up&buff.potent_flames.remains<action.fireball.execute_time&buff.potent_flames.remains>gcd&(buff.heating_up.up|action.fireball.in_flight|action.pyroblast.in_flight)

	-- pyroblast,if=buff.pyroblast.up&buff.heating_up.up&action.fireball.in_flight
	if ccrPlayerHasBuff(PYROBLAST_BUFF)
	and ccrPlayerHasBuff(HEATING_UP)
	and ccrSpellCanAttack(PYROBLAST)
	then
		ccrCastAttack(PYROBLAST)
	end
	-- nether_tempest,cycle_targets=1,if=talent.nether_tempest.enabled&((!ticking|remains<tick_time)&target.time_to_die>6)
	-- living_bomb,cycle_targets=1,if=talent.living_bomb.enabled&((!ticking|remains<tick_time)&target.time_to_die>tick_time*3)
	-- frost_bomb,if=talent.frost_bomb.enabled&(!ticking&target.time_to_die>cast_time+tick_time)
	if not ccrTargetHasMyDebuff("Living Bomb")
	and ccrSpellCanAttack("Mage Bomb")
	then
		ccrCastAttack(MAGE_BOMB)
	end
	-- inferno_blast,if=buff.pyroblast.down&buff.heating_up.up
	if not ccrPlayerHasBuff(PYROBLAST_BUFF)
	and ccrPlayerHasBuff(HEATING_UP)
	and ccrSpellCanAttack(INFERNO_BLAST)
	then
		ccrCastAttack(INFERNO_BLAST)
	end	
	-- pyroblast,if=buff.amplified.up&(cooldown.alter_time_activate.remains>0|(buff.amplified.up&trinket.stat.intellect.cooldown_remains>0))&trinket.stacking_proc.intellect.up&trinket.stacking_proc.intellect.remains<3*gcd&execute_time=gcd
	-- pyroblast,if=(cooldown.alter_time_activate.remains>0|cooldown.combustion.remains>0)&trinket.stacking_proc.intellect.up&trinket.stacking_proc.intellect.remains<3*gcd&execute_time=gcd
	-- pyroblast,if=buff.presence_of_mind.up
	if ccrPlayerHasBuff(PRESENCE_OF_MIND)
	and ccrSpellCanAttack(PYROBLAST)
	then
		ccrCastAttack(PYROBLAST)
	end
	-- fireball
	if ccrSpellCanAttack(FIREBALL) then
		ccrCastAttack(FIREBALL)
			-- inferno_blast,if=buff.pyroblast.up&buff.heating_up.down&!action.fireball.in_flight
			if ccrPlayerHasBuff(PYROBLAST_BUFF)
			and not ccrPlayerHasBuff(HEATING_UP)
			then
				ccrCastAttack(INFERNO_BLAST)
			end
	end
	-- scorch,moving=1
	if ccrPlayerIsMoving()
	and ccrSpellCanAttack(SCORCH)
	then
		ccrCastAttack(SCORCH)
	end
end
